#define _CRT_SECURE_NO_WARNINGS 1


#define MAX_SIZE 10000
class Solution20 {
public:
    bool isValid(string s) {
        int len = s.size();
        char stack[MAX_SIZE];
        int top = 0;

        for (int i = 0; i < len; i++) {
            if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
                stack[top++] = s[i];

            }
            else {
                if (top == 0)
                    return false;
                char left = stack[--top];

                if (s[i] == ')' && left != '(')
                    return false;
                if (s[i] == ']' && left != '[')
                    return false;
                if (s[i] == '}' && left != '{')
                    return false;
            }
        }

        return top == 0;
    }
};

class MyStack225 {
public:
    queue<int> queuein;
    queue<int> queueout;

    MyStack() {}

    void push(int x) {
        queueout.push(x);

        while (!queuein.empty()) {
            queueout.push(queuein.front());
            queuein.pop();
        }
        swap(queuein, queueout);
    }

    int pop() {
        int ret = queuein.front();
        queuein.pop();
        return ret;
    }

    int top() {
        int ret = queuein.front();
        return ret;
    }

    bool empty() { return queuein.empty() && queueout.empty(); }
};

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack* obj = new MyStack();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->top();
 * bool param_4 = obj->empty();
 */



class MyQueue232 {
public:
    stack<int> stackin;
    stack<int> stackout;
    MyQueue() {}

    void push(int x) { stackin.push(x); }

    int pop() {
        if (stackout.empty()) {
            while (!stackin.empty()) {
                stackout.push(stackin.top());
                stackin.pop();
            }
        }
        int ret = stackout.top();
        stackout.pop();
        return ret;
    }

    int peek() {
        if (stackout.empty()) {
            while (!stackin.empty()) {
                stackout.push(stackin.top());
                stackin.pop();
            }
        }
        int ret = stackout.top();
        return ret;
    }

    bool empty() { return stackin.empty() && stackout.empty(); }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */